<?php
namespace app\controller;

use think\exception\ValidateException;

class Upload extends Base
{
    protected $middleware = ['checkAdmin'];

    protected function initialize()
    {
        parent::initialize();
        $this->logic = new \app\logic\Upload();
    }

    public function index()
    {
        if(request()->isAjax()) {
            $params = request()->param(['page', 'limit'], [], 'trim,strip_tags');
            return $this->jsonReturn($this->logic->getList($params));
        }
        return view();
    }

    // 上传文件
    public function add()
    {
        if(request()->isAjax()) {
            $file = request()->file('file');
            return $this->jsonReturn($this->logic->upload($file));
        }
        return view();
    }

    // 删除文件
    public function delete()
    {
        $params = request()->param('ids', [], 'trim,strip_tags');
        return $this->jsonReturn($this->logic->delete($params));
    }
}